#!/usr/bin/env python
import sys
import datetime

def main():
    if len(sys.argv) < 3:
        stop_date   =   datetime.datetime.now()
    else:
        stop_date   =   datetime.datetime.strptime(sys.argv[2], "%Y-%m-%d")

    if len(sys.argv) < 2:
        start_date  =   datetime.datetime.now() - datetime.timedelta(days = 30)
    else:
        start_date  =   datetime.datetime.strptime(sys.argv[1], "%Y-%m-%d")

    for date in iterate_days(start_date, stop_date):
        for url in wiki_stat_urls(date):
            print url

def wiki_stat_urls(date):
    for hour in xrange(0, 24):
        moment  =   '%02d0000' % (hour, )
        url     =   "http://dumps.wikimedia.org/other/pagecounts-raw/%(year)04d/%(year)04d-%(month)02d/pagecounts-%(year)04d%(month)02d%(day)02d-%(moment)s.gz" % { 'year'   : date.year
        , 'month'  : date.month
        , 'day'    : date.day
        , 'moment' : moment }
        yield url

def iterate_days(start_date, end_date):
    start_date, end_date    =   min(start_date, end_date), max(start_date, end_date)

    def daterange(start_date, end_date):
        for n in range(int ((end_date - start_date).days)):
            yield start_date + datetime.timedelta(n)

    for single_date in daterange(start_date, end_date):
        yield single_date

if __name__=="__main__":
    main()
